package com.redis.common.component.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @description:
 * @Author C_Y_J
 * @create 2022/1/13 16:43
 **/
@Slf4j
public class AuthenticationFailureEventHandler implements AuthenticationFailureHandler {


    /**
     * 处理登录失败方法
     *
     * @param authenticationException 错误信息
     * @param authentication          认证信息
     * @param request                 请求信息
     * @param response                响应信息
     */
    @Async
    @Override
    public void handle(AuthenticationException authenticationException, Authentication authentication, HttpServletRequest request, HttpServletResponse response) {
        String username = authentication.getName();
        log.info("用户：{} 登录失败，异常：{}", username, authenticationException.getLocalizedMessage());
    }
}